package com.goodving.guli.server;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION;
import android.text.TextUtils;

import com.goodving.guli.bt.model.DeviceInfo;
import com.goodving.guli.bt.model.LoginData;
import com.goodving.guli.bt.model.SystemInfo;
import com.goodving.guli.server.sync.SyncServerData;
import com.goodving.guli.view.C3657a;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import cn.com.smartdevices.bracelet.config.C0886a;
import cz.msebera.android.httpclient.Header;

@SuppressLint({"NewApi"})
/* renamed from: cn.com.smartdevices.bracelet.j.j */
public class C1327j {
    static SystemInfo m11574a(Context context) {
        String str;
        String valueOf = String.valueOf(VERSION.SDK_INT);
        String str2 = C3657a.f18328f;
        try {
            str = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
        } catch (Exception e) {
            str = C3657a.f18328f;
        }
        return new SystemInfo(C1327j.m11580e(context), C1327j.m11579d(context), Build.BRAND, Build.MODEL, valueOf, str);
    }

    public static String m11575a(Context context, String str) {
        String str2 = C3657a.f18328f;
        try {
            Class loadClass = context.getClassLoader().loadClass("android.os.SystemProperties");
            return (String) loadClass.getMethod("get", new Class[]{String.class}).invoke(loadClass, new Object[]{str});
        } catch (IllegalArgumentException e) {
            throw e;
        } catch (Exception e2) {
            return C3657a.f18328f;
        }
    }

    public static void m11576a(Context context, DeviceInfo deviceInfo, AsyncHttpResponseHandler c0643h, boolean z) {
        if (context != null) {
            SystemInfo a = C1327j.m11574a(context);
            if (a != null) {
                LoginData f = C0886a.m9071f(context);
                if (f.isValid()) {
                    RequestParams a2 = ClientDataConstants.m11558a(f);
                    if (deviceInfo != null) {
                        a2.put(ClientDataConstants.aa, C3657a.f18328f + deviceInfo.getType());
                        a2.put("deviceid", deviceInfo.getDeviceId());
                        try {
                            a2.put(SyncServerData.f8331q, URLEncoder.encode(deviceInfo.getMacAddress(), AsyncHttpResponseHandler.DEFAULT_CHARSET));
                        } catch (UnsupportedEncodingException e) {
                        }
                        a2.put(ClientDataConstants.ag, deviceInfo.getFwVersion());
                        a2.put("source", deviceInfo.getSource());
                        if (!TextUtils.isEmpty(deviceInfo.getHRFwVersion())) {
                            a2.put(ClientDataConstants.ai, deviceInfo.getHRFwVersion());
                        }
                    }
                    a2.put(ClientDataConstants.ab, a.getMiuiVersionCode());
                    a2.put(ClientDataConstants.ac, a.getMiuiVersionName());
                    a2.put(ClientDataConstants.ad, a.getPhoneBrand());
                    a2.put(ClientDataConstants.ae, a.getPhoneModel());
                    a2.put(ClientDataConstants.af, a.getPhoneSystem());
                    a2.put(ClientDataConstants.ak, a.getSoftVersion());
                    String a3 = URL.m10531a(ClientConstant.f6788g);
                    if (z) {
                        AdvHttpClient.post(GuliHttpClient.asyncHttpClient, a3, a2, c0643h);
                        return;
                    } else {
                        AdvHttpClient.post(GuliHttpClient.syncHttpClient, a3, a2, c0643h);
                        return;
                    }
                }
                f.getClass();
                c0643h.onFailure(Integer.MIN_VALUE, new Header[0], new byte[0], new Throwable());
            }
        }
    }

    public static String m11577b(Context context) {
        return C1327j.m11575a(context, "ro.build.date.utc");
    }

    public static String m11578c(Context context) {
        return C1327j.m11575a(context, "ro.build.version.incremental");
    }

    public static String m11579d(Context context) {
        return C1327j.m11575a(context, "ro.miui.ui.version.code");
    }

    public static String m11580e(Context context) {
        return C1327j.m11575a(context, "ro.miui.ui.version.name");
    }
}
